<template>
	<view class="container">
		<view class="header">
			<view class="title">現有積分</view>
			<view class="num">{{ user.balance }}</view>
			<image :src="$getOSSImg('mall_bg.png')" mode="aspectFill"></image>
		</view>
		<view class="record-title">兌換記錄</view>
		<view class="record-list">
			<view v-for="item in listData" :key="item.id" class="item flex-space-b">
				<text>{{ item.goodName }}</text>
				<text>-{{ item.goodPoint }}</text>
				<text>{{ item.createTime }}</text>
			</view>
		</view>
		<view class="empty-box">
			<u-loadmore
				loadingIcon="circle"
				color="#aaa"
				:status="loadData.status"
				:loading-text="loadData.loadingText"
				:nomore-text="loadData.nomoreText"
			/>
		</view>
		<!-- 登录弹窗 -->
		<login-pop />
		<!-- 协议弹窗 -->
		<protocol-pop />
	</view>
</template>

<script>
	import { queryBtPointMallOrder } from '@/api/user'
	export default {
		data() {
			return {
				listParams: {
					hot: 1,
					sort: 'sorder',
					sortType: 'desc',
					pageNum: 1,
					pageSize: 10
				},
				listData: [],
				loadData: {
					status: 'loading',
					loadingText: '努力加載中',
					nomoreText: '沒有更多了'
				}
			}
		},
		async onLoad() {
			this.getList()
		},
		methods: {
			async getList() {
				const { pageNum, pageSize } = this.listParams
				const { data } = await queryBtPointMallOrder(this.listParams, { needLoading: false })
				if (data.result.length < pageSize) {
					this.loadData.status = 'nomore'
				}
				this.listParams.pageNum++
				this.listData = this.listData.concat(data.result)
			}
		},
		onReachBottom() {
			if (this.loadData.status === 'loading') {
				this.getList()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		min-height: 100vh;
		background: #fff;
		box-sizing: border-box;
		padding-top: 20rpx;
	}
	.header {
		position: relative;
		width: 700rpx;
		height: 220rpx;
		margin: 0 auto;
		image {
			position: absolute;
			top: 0;
			left: 0;
			width: 700rpx;
			height: 220rpx;
		}
		.title {
			position: absolute;
			top: 34rpx;
			left: 40rpx;
			z-index: 99;
			color: #fff;
			font-size: 34rpx;
		}
		.num {
			position: absolute;
			top: 50%;
			transform: translateY(-50%);
			z-index: 99;
			text-align: center;
			width: 100%;
			color: #fff;
			font-size: 60rpx;
			font-weight: bold;
		}
	}
	.record-title {
		padding: 60rpx 25rpx 30rpx;
		color: #3C9CFF;
		font-size: 34rpx;
	}
	.record-list {
		padding: 0 25rpx 20rpx;
		.item {
			line-height: 90rpx;
			border-bottom: 1px solid #f1f1ff;
			color: #333;
			font-size: 28rpx;
		}
	}
</style>